/**
 * 
 */
package com.hexacta.hrs.web.struts.actions;

import org.apache.commons.lang.StringUtils;

import com.hexacta.hrs.services.crud.CrudService;
import com.hexacta.hrs.services.timeoff.AvailableLicenseDaysService;
import com.hexacta.hrs.timeoff.AvailableLicenseDays;

/**
 * @author mfunes
 * 
 */
public class AvailableLicenseDaysAction extends CrudAbstractAction<AvailableLicenseDays> {

    private static final long serialVersionUID = 5029727449961564239L;

    private AvailableLicenseDaysService availableLicenseDaysService;

    private boolean saved = false;

    private String previousPeriodsVacationDays;

    private String currentPeriodVacationDays;

    private String studyLicenseDays;

    private String compensationDays;

    /**
     * @return the previousPeriodsVacationDays
     */
    public String getPreviousPeriodsVacationDays() {
        return previousPeriodsVacationDays;
    }

    /**
     * @param previousPeriodsVacationDays
     *            the previousPeriodsVacationDays to set
     */
    public void setPreviousPeriodsVacationDays(final String previousPeriodsVacationDays) {
        this.previousPeriodsVacationDays = previousPeriodsVacationDays;
    }

    /**
     * @return the currentPeriodVacationDays
     */
    public String getCurrentPeriodVacationDays() {
        return currentPeriodVacationDays;
    }

    /**
     * @param currentPeriodVacationDays
     *            the currentPeriodVacationDays to set
     */
    public void setCurrentPeriodVacationDays(final String currentPeriodVacationDays) {
        this.currentPeriodVacationDays = currentPeriodVacationDays;
    }

    /**
     * @return the studyLicenseDays
     */
    public String getStudyLicenseDays() {
        return studyLicenseDays;
    }

    /**
     * @param studyLicenseDays
     *            the studyLicenseDays to set
     */
    public void setStudyLicenseDays(final String studyLicenseDays) {
        this.studyLicenseDays = studyLicenseDays;
    }

    /**
     * @return the compensationDays
     */
    public String getCompensationDays() {
        return compensationDays;
    }

    /**
     * @param compensationDays
     *            the compensationDays to set
     */
    public void setCompensationDays(final String compensationDays) {
        this.compensationDays = compensationDays;
    }

    public boolean isSaved() {
        return saved;
    }

    public void setSaved(final boolean saved) {
        this.saved = saved;
    }

    public void setAvailableLicenseDaysService(final AvailableLicenseDaysService availableLicenseDaysService) {
        this.availableLicenseDaysService = availableLicenseDaysService;
    }

    @Override
    protected CrudService<AvailableLicenseDays> getCrudService() {
        return availableLicenseDaysService;
    }

    @Override
    public void validate() {

        // AvailableLicenseDays availableLicenseDays = getModel();
        clearFieldErrors();
        clearActionErrors();
        clearErrors();
        clearMessages();
        clearErrors();

        if (StringUtils.isEmpty(currentPeriodVacationDays)){
            addFieldError("Vacation Days", "Vacation Days is required");
        } else {
            if (!currentPeriodVacationDays.matches("^\\d*$")){
                addFieldError("Vacation Days", "Vacation Days must be a number greatear or equal to zero");
            }
        }
        if (StringUtils.isEmpty(previousPeriodsVacationDays)){
            addFieldError("Pending Vacation Days ", "Pending Vacation Days is required");
        } else {
            if (!previousPeriodsVacationDays.matches("^\\d*$")){
                addFieldError("Pending Vacation Days", "Pending Vacation Days must be a number greatear or equal to zero");
            }
        }
    }

    @Override
    protected void doActionsAfterSave() {
        saved = true;
    }

}
